package leetcode.median;

import java.util.Arrays;
import java.util.Comparator;

/**
 * ClassName: $452_MinArrowShots
 * Description:
 * date: 2021-10-16 22:13
 *
 * @author liyifan
 */
public class $452_MinArrowShots {
    public int findMinArrowShots(int[][] points) {
        Arrays.sort(points, (o1, o2) -> {
            if (o1[0] != o2[0]) {
                return Integer.compare(o1[0], o2[0]);
            } else {
                return Integer.compare(o1[1], o2[1]);
            }
        });
        return solution(points);
    }

    public int solution(int[][] points){
        if (points.length == 0)
            return 0;
        int res = 1;
        int pre = points[0][1];
        for (int i = 0;i < points.length;i++) {
            if (points[i][0] > pre) {
                res++;
                pre = points[i][1];
            }
        }
        return res;
    }

    public void printArray(int[][] points){
        for (int i = 0;i < points.length;i++) {
            System.out.println(points[i][0] + ", " + points[i][1]);
        }
    }
}
